//
//  HistoryItemCell.m
//  xychain_DM_iOS
//
//  Created by Jpwang on 2018/6/12.
//  Copyright © 2018年 Jpwang. All rights reserved.
//

#import "HistoryItemCell.h"

@implementation HistoryItemCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    self.contentView.backgroundColor = [UIColor clearColor];
    self.backgroundColor = [UIColor clearColor];
    self.bgIv.layer.cornerRadius = globalRadius;
    self.gradientIv.image = createGradientImage(self.gradientIv.frame.size, colorWithString(@"#2dff9e"), colorWithString(@"#15c1ff"), 1);
    if(isIPhone5()) {
        self.detailLb.font = [UIFont systemFontOfSize:8];
    } else {
        self.detailLb.font = [UIFont systemFontOfSize:10];
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)setModel:(PointHistory *)model {
    [[RACObserve(model, reasonTips) takeUntil:self.rac_prepareForReuseSignal] subscribeNext:^(id x) {
        self.titleLb.text = model.reasonTips;
    }];
    [[RACObserve(model, createTime) takeUntil:self.rac_prepareForReuseSignal] subscribeNext:^(id x) {
        self.timeLb.text = model.createTime;
    }];
    [[RACObserve(model, deltaType) takeUntil:self.rac_prepareForReuseSignal] subscribeNext:^(id x) {
        int type = [model.deltaType intValue];
        if (type == 1) {
            self.descLb.text = @"收入";
            self.descLb.textColor = colorWithString(@"#15c1ff");
        } else if (type == -1) {
            self.descLb.text = @"支出";
            self.descLb.textColor = colorWithString(@"#FF0000");
        } else {
            self.descLb.text = @"其他";
            self.descLb.textColor = colorWithString(@"#3d4358");
        }
    }];
    [[RACObserve(model, pointDelta) takeUntil:self.rac_prepareForReuseSignal] subscribeNext:^(id x) {
        NSString *text = [NSString stringWithFormat:@"%@", model.pointDelta];
        NSRange r = [text rangeOfString:@"."];
        if (r.location != NSNotFound) {
            int length = (int)MIN(text.length-r.location-1, 9);
            text = [NSString stringWithFormat:@"%@%@",[text substringToIndex:r.location+1], [text substringWithRange:NSMakeRange(r.location+1, length)]];
        }
        int type = [model.deltaType intValue];
        if (type == 1) {
            self.pointLb.textColor = colorWithString(@"#15c1ff");
        } else if (type == -1) {
            self.pointLb.textColor = colorWithString(@"#FF0000");
        } else {
            self.pointLb.textColor = colorWithString(@"#3d4358");
        }
        self.pointLb.text = text;
    }];
    [[RACObserve(model, businessId) takeUntil:self.rac_prepareForReuseSignal] subscribeNext:^(id x) {
        if ([model.deltaType intValue] != 1 && model.businessId && model.businessId.length>0) {
            self.detailLb.text = model.businessId;
            self.topMargin.constant = 5;
        } else {
            self.detailLb.text = @"";
            self.topMargin.constant = 18;
        }
    }];
}

@end
